package cn.stylefeng.guns.modular.third.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.core.util.DateUtil;
import cn.stylefeng.guns.modular.third.entity.ThirdManagementStatistics;
import cn.stylefeng.guns.modular.third.model.params.ThirdManagementStatisticsParam;
import cn.stylefeng.guns.modular.third.service.ThirdManagementStatisticsService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.guns.sys.modular.system.service.UserService;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 运输管理统计控制器
 */
@Controller
@RequestMapping("/thirdManagementStatistics")
public class ThirdManagementStatisticsController extends BaseController {

    private String PREFIX = "/third/thirdManagementStatistics";

    @Autowired
    private ThirdManagementStatisticsService thirdManagementStatisticsService;

    @Autowired
    private UserService userService;

    /**
     * 跳转到主页面
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/thirdManagementStatistics.html";
    }

    /**
     * 新增页面
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/thirdManagementStatistics_add.html";
    }

    /**
     * 打印页面
     */
    @RequestMapping("/print")
    public String print() {
        return PREFIX + "/printing.html";
    }

    /**
     * 编辑页面
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/thirdManagementStatistics_edit.html";
    }

    /**
     * 新增接口
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ThirdManagementStatisticsParam thirdManagementStatisticsParam) {
    	ThirdManagementStatisticsParam to = new ThirdManagementStatisticsParam();
    	to.setDates(DateUtil.getDate());
    	int count = thirdManagementStatisticsService.countBydate(to);
    	DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyyMMdd");//设置日期格式
    	thirdManagementStatisticsParam.setOrderNumber(LocalDateTime.now().format(fmt)+(count+1));
    	thirdManagementStatisticsParam.setStatus("未付");
        this.thirdManagementStatisticsService.add(thirdManagementStatisticsParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ThirdManagementStatisticsParam thirdManagementStatisticsParam) {
        this.thirdManagementStatisticsService.update(thirdManagementStatisticsParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ThirdManagementStatisticsParam thirdManagementStatisticsParam) {
        this.thirdManagementStatisticsService.delete(thirdManagementStatisticsParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ThirdManagementStatisticsParam thirdManagementStatisticsParam) {
        ThirdManagementStatistics detail = this.thirdManagementStatisticsService.getById(thirdManagementStatisticsParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ThirdManagementStatisticsParam thirdManagementStatisticsParam,String condition  ,String startTime,String endTime) {
    	if (ToolUtil.isNotEmpty(startTime) && ToolUtil.isNotEmpty(endTime)) {
    		thirdManagementStatisticsParam.setDates("'"+startTime+"' and '"+endTime+"'");
    	} 
        return this.thirdManagementStatisticsService.findPageBySpec(thirdManagementStatisticsParam,condition);
    }

}


